const express = require('express')
const bodyParser = require('body-parser')
const session = require('express-session')
const router = require('./router.js')
const config = require('./config.js')

const app = express()

app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

app.use(session({
	secret: 'vip',
	resave: false,
	saveUninitialized: false
}))

app.use('/api', router)

app.use((err, req, res, next) => {
	res.status(500).json({
		error : err.message
	})
})

app.listen(config.port, ()=> {
	console.log('server is running 3000...')
})